package com.tiancheng.trade.order.service;

import com.baomidou.mybatisplus.extension.service.IService;
import com.tiancheng.trade.commom.core.data.PageInfo;
import com.tiancheng.trade.commom.core.data.Result;
import com.tiancheng.trade.commom.core.exception.BusinessException;
import com.tiancheng.trade.order.bo.RefundNotifyBO;
import com.tiancheng.trade.order.bo.RefundOrdersDetailSubmitBO;
import com.tiancheng.trade.order.bo.cmq.RefundMsgBO;
import com.tiancheng.trade.order.bo.cmq.ScrmOrder;
import com.tiancheng.trade.order.model.RefundOrdersDetail;
import com.tiancheng.trade.order.vo.admin.QueryRefundVO;
import com.tiancheng.trade.order.vo.admin.QueryTotalRefundVO;
import com.tiancheng.trade.order.vo.admin.res.RefundDetailResVO;
import com.tiancheng.trade.order.vo.admin.res.RefundResVO;
import com.tiancheng.trade.order.vo.api.ScrmOrderQueryVO;
import com.tiancheng.trade.order.vo.api.res.RefundBatchResVO;
import com.tiancheng.trade.order.vo.api.res.RefundCreateResVO;
import com.tiancheng.trade.order.vo.app.RefundQueryVO;
import com.tiancheng.trade.order.vo.app.res.RefundQueryResVO;
import com.tiancheng.trade.order.vo.open.order.OpenRefundVO;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * 退款详情Service接口
 *
 * @author kellen
 * @date 2024-03-18
 */
@Service
public interface RefundOrdersDetailService extends IService<RefundOrdersDetail> {

	RefundOrdersDetail queryRefundOrderDetailsById(Long id);

	RefundDetailResVO queryRefundOrderByRefundId(String refundId);


	/**
	 * 批量更新退款单
	 * @param submitBOS
	 * @return
	 */
	int updateBatch(List<RefundOrdersDetailSubmitBO> submitBOS);

	/**
	 * 根据子订单查询退款记录
	 * @param subId
	 * @return
	 */
	List<RefundOrdersDetail> findBySubId(String subId);

	/**
	 * 根据子订单查询退款成功的
	 * @param subId
	 * @return
	 */
	List<RefundOrdersDetail> findSuccessBySubId(String subId);

	/**
	 * 查询退款订单
	 *
	 * @param userId
	 * @param refundId
	 * @return
	 */
	Result queryRefund(String userId, String refundId);


	/**
	 * 构造获取重复支付的退款对象
	 *
	 * @param uid
	 * @param refundMsgBO
	 * @return
	 * @throws BusinessException
	 */
	List<RefundOrdersDetail> getRefundForRepeatPay(String uid, RefundMsgBO refundMsgBO);

	/**
	 * 重复支付退款
	 *
	 * @param refundOrdersDetails
	 * @param refundMsgBO
	 * @throws BusinessException
	 */
	void saveRefundForRepeatPay(List<RefundOrdersDetail> refundOrdersDetails, RefundMsgBO refundMsgBO);

	/**
	 * 发起退款
	 *
	 * @param refundOrdersDetails
	 * @param refundMsgBO
	 * @throws BusinessException
	 */
	void refundForRepeatPay(List<RefundOrdersDetail> refundOrdersDetails, RefundMsgBO refundMsgBO) throws BusinessException;

	/**
	 * 根据退款Id查询
	 *
	 * @param refundId
	 * @return
	 */
	RefundOrdersDetail get(String refundId);

	/**
	 * 根据主订单号查询退款记录
	 * @param orderId
	 * @return
	 */
	List<RefundOrdersDetail> getRefundList(String orderId);

	PageInfo<RefundResVO> queryRefundList(QueryRefundVO queryRefundVO);

	/**
	 * 查询退款成功的数量、总金额
	 * @param queryTotalRefundVO
	 * @return
	 */
	Map<String, Long> queryTotal(QueryTotalRefundVO queryTotalRefundVO);

	/**
	 * 根据子订单号查询退款
	 * @param suborderId
	 * @return
	 */
	List<RefundOrdersDetail> getSubRefund(String suborderId);

	/**
	 * 移动端查询退款单
	 * @param refundQueryVO
	 * @return
	 */
	PageInfo<RefundQueryResVO> findForApp(RefundQueryVO refundQueryVO);

	/**
	 * 查询汇总退款总金额，根据批次
	 * @param uid
	 * @param paymentId
	 * @return
	 */
	RefundBatchResVO getByPaymentId(String uid, String paymentId);

	/**
	 * 查询退款成功子订单
	 * @param orderIds 主订单id集合
	 * @param subOrderIds 子订单id集合
	 * @return 退款成功结果集合
	 */
	List<RefundOrdersDetail> querySuccessRefundBySubOrderIds(Set<String> orderIds, Set<String> subOrderIds);

	/**
	 * 苹果退款回调处理
	 * @param refundNotifyBO
	 */
	List<RefundOrdersDetail> saveApplePayResult(RefundNotifyBO refundNotifyBO);

	PageInfo<ScrmOrder> queryPayOrderAndSubOrder(ScrmOrderQueryVO queryVO);

	/**
	 *
	 * @param refundId 退款订单id
	 * @return
	 */
	List<RefundOrdersDetail> queryByRefundId(String refundId);
}
